package com.tool;

import java.io.IOException;
import java.util.SortedMap;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.tool.util.SecurityUtils;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class HttpToPost {

	private static final Logger LOGGEG = LoggerFactory.getLogger(HttpToPost.class);

	public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

	public static void main(String[] args) {
		Gson gson = new Gson();

		OkHttpClient client = new OkHttpClient();

		String url = "http://127.0.0.1:8083/security-transaction-service/api/rule/withdraw";
		String key = "R4xF+WOsSZIpnL3n30Ufgg";
		SortedMap<String, String> paramMap = new TreeMap<String, String>();
		paramMap.put("attr", "uid");
		paramMap.put("rule", "8192");
		paramMap.put("values", "111142697");
		paramMap.put("refModules", "otc");
		paramMap.put("timestamp", "1587225839619");
		String token = SecurityUtils.getSign(paramMap, key);
		paramMap.put("token", token);

		String param = gson.toJson(paramMap);
//		MediaType mediaType = MediaType.Companion.parse("application/json;charset=utf-8");
//		RequestBody requestBody = RequestBody.Companion.create(param, JSON);
//
//		Request request = new Request.Builder().post(requestBody).url(url).build();
//
//		client.newCall(request).enqueue(new Callback() {
//			@Override
//			public void onFailure(Call call, IOException e) {
//				LOGGEG.info("onFailure: 失败 {} ", e.getMessage());
//			}
//
//			@Override
//			public void onResponse(Call call, Response response) throws IOException {
//				String result = response.body().string();
//				LOGGEG.info("onResponse: {}", result);
//			}
//		});

	}

}